const http = uni.$u.http

// 获取广告轮播图列表信息
export const getAdvert = (data) => http.get('/advertisingspace/advertising?space=1,2,3')
// 批量获取动态列表信息
export const getFeeds = (data) => http.get('/feeds')
// 获取指定 ID 动态详情
export const getfeedsInfo = params => http.get('/feeds/' + params.id)
// 获取指定 ID 评论详情
export const getFeedComments = params => http.get('/feeds/' + params.id + '/comments')


// 批量获取资讯列表信息
export const getNews = (data) => http.get('/news')
// 获取指定 ID 资讯详情信息
export const getNewsInfo = params => http.get('/news/' + params.id)
// 获取指定 ID 资讯评论详情
export const getNewComments = params => http.get('/news/' + params.id + '/comments')

// 获取当前用户登录相关的通知消息
export const getUserMsg = () => http.get('/user/counts')
// 查找用户信息
export const findUser = params => http.get('/users/' + params.name)

// 点赞动态
export const likeThisFeed = params => http.post('/feeds/' + params.id + '/like')
// 取消点赞动态
export const unlikeThisFeed = params => http.delete('/feeds/' + params.id + '/unlike')
// 评论一条动态
export const commentOneFeed = params => http.post('/feeds/' + params.id + '/comments', {
	body: params.body
})

// 点赞资讯
export const likeThisNew = params => http.post('/news/' + params.id + '/likes')
// 取消点赞资讯
export const unlikeThisNew = params => http.delete('/news/' + params.id + '/likes')
// 评论一条资讯
export const commentOneInfo = params => http.post('/news/' + params.id + '/comments', {
	body: params.body
})

// 文件上传操作
export const uploadFile = async file =>{
		let rfile = file
		// #ifdef MP-WEIXIN
		rfile = uni.getFileSystemManager().readFileSync(file.path)
		// #endif
		
		// 将文件写入后台系统系统
		let ufile = await uni.uploadFile({
			url: vm.$u.http.config.baseUrl + '/files',
			header: {
				Authorization: "Bearer " + uni.getStorageSync("token"),
			},
			name: 'file',
			file: rfile,
			filePath: file.path
		});
		console.log(JSON.parse(ufile[1].data))
		return JSON.parse(ufile[1].data)
	}